<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with try catch - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=try+catch</link>
      <pubDate>Sun, 08 Aug 2021 19:15:06 +0000</pubDate>
         <description>Tagged with try catch - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedtry+catch/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Try-Catch with LoadImage()</title>
      <link>https://forum.processing.org/two/discussion/26996/try-catch-with-loadimage</link>
      <pubDate>Thu, 22 Mar 2018 19:02:29 +0000</pubDate>
      <dc:creator>jacopom</dc:creator>
      <guid isPermaLink="false">26996@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to safely load an image from  the web into a PImage in Processing 3.
I tried to adapt the try-catch example from <a rel="nofollow" href="https://processing.org/reference/try.html">the website</a> but IOExceptions was not the right kind of exception, I tried with a general Exception but that doesn't seem to work either.
How would I find the right kind of exception to try to catch?
Is the  following snippet the right thing (other than the exception kind or are there better ways to check for errors like this one?</p>

<pre lang="java">PImage webImg;
String urls[];

void setup() {
  size(200,200);
  
  urls = new String[2];
  // working URL
  urls[0] = "https://"+"processing.org/img/processing-web.png";
  // bad URL
  urls[1] = "https://"+"**********.org/img/processing-web.png";
}

void draw() {
  
  background(0);
    try {
      webImg = loadImage(urls[frameCount%2], "png");
    } catch (Exception e) {
    //e.printStackTrace();
    webImg = null;
    println("Error!");
  }
  
  if (webImg != null) {
    println("It Worked!");
   image(webImg,0,0); 
  }

}</pre>
]]></description>
   </item>
   <item>
      <title>How to retrieve where an error happens</title>
      <link>https://forum.processing.org/two/discussion/25840/how-to-retrieve-where-an-error-happens</link>
      <pubDate>Fri, 05 Jan 2018 19:52:28 +0000</pubDate>
      <dc:creator>SimJ</dc:creator>
      <guid isPermaLink="false">25840@/two/discussions</guid>
      <description><![CDATA[<p>I get an error message that I wrote myself in a method, but I can't figure out in which centext it happens.</p>

<p>Example :</p>

<pre><code>void aMethod() {
 if(problem){print("Error");}
}
</code></pre>

<p>The method aMethod is used in a lots of different contexts in my sketch. How can I modify my error message so I get something like the stack trace of an error ?</p>
]]></description>
   </item>
   <item>
      <title>Catch exception with SQL Library</title>
      <link>https://forum.processing.org/two/discussion/23239/catch-exception-with-sql-library</link>
      <pubDate>Wed, 28 Jun 2017 07:10:07 +0000</pubDate>
      <dc:creator>progressivemonkey</dc:creator>
      <guid isPermaLink="false">23239@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I'm using the Bezier SQL library, and have trouble handling exceptions. In the below code, I'm trying to connect to a database using bad credentials, which throws the exception:</p>

<p><code>java.sql.SQLException: Access denied for user 'thisisnottherightuser'@'92.106.188.139' (using password: YES)</code></p>

<p>However, putting the database connection in a try/catch statement does not catch the exception, and if the catch is written as <code>catch(SQLException e)</code>, I get a compile error saying "This exception is never thrown from the try statement body", even though it clearly does throw it.</p>

<p>Does anyone have a hint as to what I'm doing wrong?</p>

<p>Thanks!!</p>

<pre><code>import de.bezier.data.sql.mapper.*;
import de.bezier.data.sql.*;

String dbHost    = "89.216.113.243:3306";
String dbUser    = "thisisnottherightuser";
String dbPass    = "thisisnottherightpassword";
String dbName    = "testname";

MySQL             mainSQL;

void setup() {
  mainSQL    = new MySQL(this, dbHost, dbName, dbUser, dbPass);
  try {
     mainSQL.connect(); 
  } catch (Exception e) {
    println("there was a problem"); 
  }
  exit();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Sequential Problem</title>
      <link>https://forum.processing.org/two/discussion/11640/sequential-problem</link>
      <pubDate>Fri, 10 Jul 2015 03:44:23 +0000</pubDate>
      <dc:creator>Novaah</dc:creator>
      <guid isPermaLink="false">11640@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys. I am working on a small game where clicking groups of matching bubbles has them all pop. I have encountered a problem with my method in bubble.check() due to the fact that the bubble is killed when it checks one side so if the bubble you click has neighbors on both sides it only checks one side (Goes through the try catch statements sequentially so once one matches the others don't work due to the bubble not existing). Removing the this.killBubble() from the try catches causes the sketch to crash. Does anyone see a work-around of this method?</p>

<pre><code>//Variables for drawing bubbles
int bubbleDiameter = 25;
int bubbleOffset = bubbleDiameter/2 + 10;

//Colors set to names for readability
color blue = color(0, 204, 251);
color red = color(254, 42, 2);
color green = color(47, 252, 25);
color yellow = color(254, 236, 76);
color pink = color(250, 1, 138);

//Arrays conataining properties of each bubble
int bubbleColor[][] = new int[20][25]; //Contains an int corresponding to the bubble's color
boolean bubbleHover[][] = new boolean[20][25]; //When mouse is hovering above bubble this is true
Bubble bubble[][] = new Bubble[20][25];

void setup() {

  size(520, 700); //Create window
  colorGen();
  for(int x = 0; x &lt; 20; x++) {
    for(int y = 0; y &lt; 25; y++) {
      bubble[x][y] = new Bubble(x, y);

    }
  }

}

void draw() {
  background(192, 192, 255);

  scoreBar();

  for(int x = 0; x &lt; 20; x++) {
    for(int y = 0; y &lt; 25; y++) {  
      bubble[x][y].drawBubble();
    }
  }
  checkHover();

}

class Bubble {

  boolean living;
  int xPos;
  int yPos;
  int col;

  //Bubble class

  //Constructor for bubble
  public Bubble(int x, int y) {

    this.living = true; //State of bubble
    this.xPos = x; //Gives the x position of the bubble in the array
    this.yPos= y; //Gives the y position of the bubble in the array
    this.col = bubbleColor[x][y]; //Sets color value to that in the array generated by colorGen()
  }

  //
  void killBubble() {
    this.living = false;
    this.col = 5;
  }

  void check(boolean b) {
   this.check();
   this.killBubble(); 
  }

  void check() {
    boolean n = false;
    try {
      print("0\n");
      if (bubble[this.xPos+1][this.yPos].living) {
        if(this.col == bubble[this.xPos+1][this.yPos].col) {
          this.killBubble();
          bubble[this.xPos+1][this.yPos].check(true);
        }
      }
      print("1\n");
      if (bubble[this.xPos-1][this.yPos].living) {
        if(this.col == bubble[this.xPos-1][this.yPos].col) {
          this.killBubble();
          bubble[this.xPos-1][this.yPos].check(true);
        }
      }
      print("2\n");
      if (bubble[this.xPos][this.yPos+1].living) {
        if(this.col == bubble[this.xPos][this.yPos+1].col) {
          this.killBubble();
          bubble[this.xPos][this.yPos+1].check(true);
        }
      }
      print("3\n");
      if (bubble[this.xPos][this.yPos-1].living) {
        if(this.col == bubble[this.xPos][this.yPos-1].col) {
          this.killBubble();
          bubble[this.xPos][this.yPos-1].check(true);
        }
      }  

    }
    catch(Exception border) {
      print(border.toString());
    }
  }  

  void drawBubble() {
    if(this.living) {
      //Colors bubble based on color value from array
      if(this.col == 0) {
        fill(red);  
      }
      else if(this.col == 1) {
        fill(blue); 
      }
      else if(this.col == 2) {
        fill(green);  
      }
      else if(this.col == 3) {
        fill(yellow);  
      }
      else if(this.col == 4) {
        fill(pink); 
      }
      //Draws bubble in grid
      ellipse(bubbleOffset + xPos*bubbleDiameter, bubbleOffset + yPos*bubbleDiameter, bubbleDiameter, bubbleDiameter);
    }
  }
}

//Runs when mouse is clicked
void mouseClicked() {
  for(int x = 0; x &lt; 20; x++) {
    for(int y = 0; y &lt; 25; y++) { 
      if(bubbleHover[x][y] == true) { //Checks which bubble the mouse is over when clicked
        try {
          bubble[x][y].check();
        }
        catch(Exception e) {}
      }
    }
  }  
}

//Checks if mouseX and mouseY fall within a certain bubble's area
void checkHover() {
  for(int x = 0; x &lt; 20; x++) {
    for(int y = 0; y &lt; 25; y++) { 
      if(mouseX &gt; bubbleOffset + x*bubbleDiameter - bubbleDiameter/2 &amp;&amp; mouseX &lt; bubbleOffset + x*bubbleDiameter + bubbleDiameter/2 
        &amp;&amp; mouseY &gt; bubbleOffset + y*bubbleDiameter - bubbleDiameter/2 &amp;&amp; mouseY &lt; bubbleOffset + y*bubbleDiameter + bubbleDiameter/2) {

        bubbleHover[x][y] = true; //Sets hover to true if locations intersect
      }
      else {
        bubbleHover[x][y] = false; //Sets hover to false if there is no intersection
      }
    }
  }
}

//Generates random colors and assigns them to positions in an array
void colorGen() {
  for(int x = 0; x &lt; 20; x++) {
    for(int y = 0; y &lt; 25; y++) {
      bubbleColor[x][y] = floor(random(5));
    }
  }
}

//Creates score box
void scoreBar() {
  textSize(32);
  fill(pink);
  text("Score:", 10, 675); 
  text("Time:", width/2, 675);
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>